#include <iostream>
#include "MsgParser.h"

#ifndef DOXYGEN_SHOULD_SKIP_THIS
/**
 * Scans given input string and finds first instance
 * of the delimiter.
 * Once such is found, the substring is extracted,
 * stored in tokens array and then removed from input string.
 * Repeated for tokensCount times
 */
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
void MsgParser::extractTokens(const string inputString, const string delimiter,
		const int tokensCount, string* tokens) {

	// copy input string
	string workString = inputString;

	// scan message string and split by delimiter
	for (int i = 0; i < tokensCount; i++) {

		// parse current token
		string token = workString.substr(0, workString.find(delimiter));

		// add current token to array
		tokens[i] = token;

		// move to next token
		workString.erase(0, workString.find(delimiter) + delimiter.length());
	}
}
